package com.sky.agent.utils;

import cn.hutool.core.date.DateUtil;

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.Date;


public class DateUtilJava8 {
    private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");


    public static String setTime(Date date, int hour, int minute, int second) {
        if (date == null) {
            return null;
        }


        LocalDateTime ldt = LocalDateTime.ofInstant(date.toInstant(), ZoneId.systemDefault());


        LocalDateTime customLdt = ldt.withHour(hour).withMinute(minute).withSecond(second);


        return DateUtil.format(Date.from(customLdt.atZone(ZoneId.systemDefault()).toInstant()), "yyyy-MM-dd HH:mm:ss");
    }
}

